package com.lzw.security.exception;

import com.lzw.security.ov.Status;
import com.lzw.security.ov.UserOV;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-3-28 22:51
 * @description：异常控制器
 * @modified By：
 * @version:
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 处理，实际为捕捉全局异常
     *
     * @param exception 全局异常
     * @return 具体异常信息 后面那个是500报错内容是服务器内部异常
     */
    @ExceptionHandler(Exception.class)
    public UserOV handlerException(Exception exception) {
        //当未知异常发生时，将信息弹出堆栈
        exception.printStackTrace();
        UserOV userOV = new UserOV();
        userOV.getMeta().setStatus(500).setMessage("未知异常");
        return userOV;
    }
    @ExceptionHandler(TidcNulException.class)
    public UserOV handlerException(TidcNulException exception){
        UserOV userOV = new UserOV();
        userOV.getMeta().setStatus(445).setMessage(exception.getMessage());
        return userOV;
    }
    @ExceptionHandler(MysqlUpdateException.class)
    public UserOV handlerException(MysqlUpdateException exception){
        UserOV userOV = new UserOV();
        userOV.getMeta().setStatus(505).setMessage(exception.getMessage());
        return userOV;
    }
}
